package net.zjitc.controller;

import net.zjitc.pojo.Admin;
import net.zjitc.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;

@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;
    @PostMapping("login")
    public String login(Admin admin, Model model) throws IOException {
        //查询当前用户是否存在
        Admin user = adminService.findAdmin(admin.getUsername());
        if (user!=null){
            model.addAttribute("msg","登录成功");
            return "success";
        }
        model.addAttribute("msg","登录失败 ");
        return "index";
    }
}

